package com.fly.user.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.fly.common.model.UserEntity;
import com.fly.common.vo.user.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * @description 用户对象数据库映射
 * @author: fly
 * @date: 2018/11/20 14:37
 */
@Repository
public interface UserMapper extends BaseMapper<UserEntity> {

    /**
     * 获取用户数量
     *
     * @return 用户数量
     */
    @Select(value = "select count(*) from user where is_delete = '0'")
    Long queryUserCount();

    /**
     * 注解方式获取用户信息
     *
     * @param userId 用户主键
     * @return 用户信息
     */
    @Select(value = "select user_id, real_name, mobile, address, work_num from user where is_delete = '0' and user_id = #{userId}")
    UserVO findById(@Param("userId") Long userId);

    /**
     * 根据账户获取用户信息
     *
     * @param userName 账户
     * @return 用户信息
     */
    @Select(value = "select user_id, real_name, mobile, address, work_num from user where is_delete = '0' and user_name = #{userName}")
    UserEntity findByUserName(@Param("userName") String userName);
}
